package com.ks.core.framework.cpsupload.demos.orderpayinvoice.orderhandler;

import com.ks.core.framework.cpsupload.demos.orderpayinvoice.constant.InvoiceType;
import com.ks.core.framework.cpsupload.demos.orderpayinvoice.constant.OrderType;
import com.ks.core.framework.cpsupload.demos.orderpayinvoice.constant.PaymentType;
import com.ks.core.framework.cpsupload.demos.orderpayinvoice.event.InvoiceCallbackEvent;
import com.ks.core.framework.cpsupload.demos.orderpayinvoice.event.PaymentCallbackEvent;
import com.ks.core.framework.cpsupload.demos.orderpayinvoice.paytemplate.ConferencePaymentProcessor;
import com.ks.core.framework.cpsupload.demos.orderpayinvoice.paytemplate.PaymentTemplate;

import java.math.BigDecimal;

// 主服务入口
public class OrderSystem {
    public static void main(String[] args) {
        // 创建注册费订单
        Order order = OrderFactory.createOrder(OrderType.CONF_REGISTRATION);
        order.setOrderId("REG123");
        order.setAmount(new BigDecimal("1000.00"));
        ((ConferenceOrder) order).setPackageId("PKG-GOLD");
        
        // 使用支付模板进行支付
        PaymentTemplate paymentProcessor = new ConferencePaymentProcessor();
        paymentProcessor.processPayment(order, PaymentType.WECHAT, new BigDecimal("500.00"));
        paymentProcessor.processPayment(order, PaymentType.ALIPAY, new BigDecimal("500.00"));
        
        // 处理支付回调
        PaymentCallbackEvent event = new PaymentCallbackEvent();
        event.setOrderId("REG123");
        event.setAmount(new BigDecimal("500.00"));
        event.setSuccess(true);
        event.setPaymentType(PaymentType.WECHAT);
        
        new PaymentCallbackHandler().processCallback(event);
        
        // 发票回调处理
        InvoiceCallbackEvent invoiceEvent = new InvoiceCallbackEvent();
        invoiceEvent.setOrderId("REG123");
        invoiceEvent.setInvoiceType(InvoiceType.BLUE);
        invoiceEvent.setFileUrl("https://example.com/invoice.pdf");
        invoiceEvent.setStatus(InvoiceCallbackEvent.InvoiceStatus.SUCCESS);
        
        new InvoiceService().handleInvoiceCallback(invoiceEvent);
        
        // 处理退款
        new RefundService().refund(order, PaymentType.WECHAT, new BigDecimal("200.00"));
        new RefundService().fullRefund(order);
    }
}